#include "TextConvertApplication.h"

#include "TextConvertWindow.h"

struct _TextConvertApplication
{
        AdwApplication parent_instance;
};

G_DEFINE_TYPE(TextConvertApplication,
              text_convert_application,
              ADW_TYPE_APPLICATION)

static void
text_convert_application_activate(GApplication *g_app)
{
        TextConvertApplication *app = TEXT_CONVERT_APPLICATION(g_app);
        g_assert(TEXT_CONVERT_IS_APPLICATION(app));
        GtkWindow *window;

        window = gtk_application_get_active_window(GTK_APPLICATION(app));
        if (!window) {
                window = GTK_WINDOW(g_object_new(TEXT_CONVERT_TYPE_WINDOW,
                                                 "application",
                                                 app,
                                                 NULL));
        }
        gtk_window_present(window);
}

static void
text_convert_application_finalize(GObject *object)
{
        G_OBJECT_CLASS(text_convert_application_parent_class)->finalize(object);
}

static void
text_convert_application_class_init(TextConvertApplicationClass *klass)
{
        G_OBJECT_CLASS(klass)->finalize = text_convert_application_finalize;
        G_APPLICATION_CLASS(klass)->activate =
                text_convert_application_activate;
}

static void
text_convert_application_init(TextConvertApplication *self)
{}

TextConvertApplication *
text_convert_application_new(const char       *application_id,
                             GApplicationFlags flags)
{
        return TEXT_CONVERT_APPLICATION(
                g_object_new(TEXT_CONVERT_TYPE_APPLICATION,
                             "application-id",
                             application_id,
                             "flags",
                             flags,
                             NULL));
}